package com.ysd.lis.util.CA;

import java.util.Arrays;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import org.apache.commons.codec.binary.Base64;

public class Hmac {
	
	public String hmac(String message,String secret){
		String hash=null;
		try{
		
		Mac HmacSHA256=Mac.getInstance("HmacSHA256");
		SecretKeySpec secret_key = new SecretKeySpec(secret.getBytes(), "HmacSHA256");
		HmacSHA256.init(secret_key);
		hash = Base64.encodeBase64String(HmacSHA256.doFinal(message.getBytes()));
		}catch(Exception e){
			e.getStackTrace();
		}
	  return hash;
	}	
	
	public  String  ascii(String message) {
	    String instr = message;
	    String str = null;
	   try{  
		String []chars = instr.split("&");
	    Arrays.sort(chars);	  
	    for ( String item:chars) {
	    	
	    	str+=item+"&";
	    	
	    }}catch(Exception e){
	    	e.printStackTrace();
	    }
		return str.substring(4,str.length()-1);
	    
	}
	
}
